<?php

namespace app\api\controller;

class Detail extends Base
{
    public function index () {
        $dataArr = []; // 本页数据集合
        $id = $this->request->get('id');
        if(!isset($id)) {
            // 如果数据不存在 抛出404异常
            return $this->buildFailed('-1', 'id不能为空');
        }
        /**
         *   获取详情
         *   @param id
         *   @date 2019/12/3
         *   @author Xiaohui Zeng
         */
        $detail = new Content();
        $detailData = $detail->detail($id);
        // 如果id文章页面存在
        $dataArr['CmsDetail'] = $detailData;

        /**
         *   获取随机文章
         *   @param $num 默认4
         *   @date 2019/12/3
         *   @author Xiaohui Zeng
         */
        $randomData = $detail->getRandom(4);
        $dataArr['CmsRandomData'] = $randomData;

        return $this->buildSuccess(['list' => $dataArr], '获取成功'); // 返回json 用于调试
    }
}